1 # import all functions from the tkinter
2 from tkinter import *
3
4 from tkinter import ttk
5
6 #import Calendar module
7 import calendar
8
9 def showCal():
10
11 #new calendar window
12 new_window = Tk()
13
14 #setting the background color of GUI application
15 new_window.config(background = 'white')
16
17 #setting the title of the GUI application
18 new_window.title("Calendar")
19
20 #setting the geometry of the GUI application
21 new_window.geometry('550x600')
22
23 # get method returns current text as string
24 fetch_year = int(year_field.get())
25
26 # calendar method of calendar module return
27 # the calendar of the given year .
28 cal_content = calendar.calendar(fetch_year)
29
30 # Create a label for showing the content of the calender
31 cal_year = Label(new_window, text = cal_content, font = "Consolas 10 bold")
32
33 # grid method is used for placing
34 # the widgets at respective positions
35 # in table like structure.
36 cal_year.grid(row = 5, column = 1, padx = 20)
37
38 # start the GUI
39 new_window.mainloop()
40
41
42 if __name__=='__main__':
43
44 #Create the basic gui window
45 root = Tk()
46
47 #setting the background color of GUI application
48 root.config(background = 'white')
49
50 #setting the title of the GUI application
51 root.title("HOME")
52
53 #setting the geometry of the GUI application
54 root.geometry('500x400')
55
56 # Create a CALENDAR : label with specified font and size
57 cal = Label(root, text = "Welcome to the calendar Application", bg = "Red", font = ("times", 20, 'bold'))
58
59 #Create a Year label : a label to ask the user for year
60 year = Label(root, text = 'Please enter a year',bg = 'Green')
61
62 #Create a Year Entry : Entry
63 year_field = Entry(root)
64
65 # Create a Show Calendar Button and attached to showCal function
66 Show = Button(root, text = "Show Calendar", fg = "Black", bg = "Light Green", command = showCal)
67
68 # Create a Exit Button and attached to exit function
69 Exit = Button(root, text = "Exit", fg = "Black", bg = "Light Green", command = exit)
70
71 # grid method is used for placing
72 # the widgets at respective positions
73 # in table like structure.
74 cal.grid(row = 1, column = 1)
75
76 year.grid(row = 2, column = 1)
77
78 year_field.grid(row = 3, column = 1)
79
80 Show.grid(row = 4, column = 1)
81
82 Exit.grid(row = 6, column = 1)
83
84 # start the GUI
85 root.mainloop()